package chapter14;

import java.lang.reflect.Method;

import thinkingJava.chapter14.A;
import thinkingJava.chapter14.HiddenC;

public class HiddenImplementation {
	public static void main(String[] args) throws Exception {
		A a = HiddenC.makeA();
		a.f();
		System.out.println(a.getClass().getSimpleName());
//		if (a instanceof C) {
//			C c = (C) a;
//			c.g();
//		}
		callHiddenMethod(a , "g");
		callHiddenMethod(a , "u");
		callHiddenMethod(a , "v");
		callHiddenMethod(a , "w");
	}
	public static void callHiddenMethod(Object a, String methodName) throws Exception {
		Method m = a.getClass().getDeclaredMethod(methodName);
		m.setAccessible(true);
		m.invoke(a);
	}
}
